package com.neuedu.oasystem.view;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

import com.neuedu.oasystem.entity.MeetingPlace;
import com.neuedu.oasystem.entity.Participant;
import com.neuedu.oasystem.entity.PrepareMeeting;
import com.neuedu.oasystem.service.impl.MeetingPlaceServiceImpl;
import com.neuedu.oasystem.service.impl.ParticipantServiceImpl;
import com.neuedu.oasystem.service.impl.PrepareMeetingServiceImpl;

/**
 * 
 * @author admin
 *
 */
public class MeetingView {
	static ParticipantServiceImpl participantServiceImpl = new ParticipantServiceImpl();
	static Participant participant = null;

	static MeetingPlaceServiceImpl meetingPlaceServiceImpl = new MeetingPlaceServiceImpl();
	static MeetingPlace meetingPlace = null;

	static PrepareMeetingServiceImpl prepareMeetingServiceImpl = new PrepareMeetingServiceImpl();
	static PrepareMeeting prepareMeeting = null;

	List<Participant> list = new ArrayList<Participant>();
	static Scanner scanner = new Scanner(System.in);

	private static void insertParticipant() {
		int empId = 0;
		int meetingId = 0;

		System.out.print("请输入员工编号：");
		try {
			String name = scanner.nextLine();
			empId = Integer.parseInt(name);
		} catch (Exception e) {
			System.out.println("请输入数字:");
		}
		System.out.print("请输入会议编号：");
		try {
			String idsString = scanner.nextLine();
			meetingId = Integer.parseInt(idsString);
		} catch (Exception e) {
			System.out.println("请输入数字:");
		}
		System.out.print("请输入会议主题：");
		String conferenceTheme = scanner.nextLine();

		System.out.print("到场情况：");
		String presentSituation = scanner.nextLine();

		System.out.println("是否添加参与人员信息:");
		System.out.println("是否添加信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			participant = new Participant(empId, meetingId, conferenceTheme, presentSituation);
			boolean bool = participantServiceImpl.add(participant);
			if (bool) {
				System.out.println("新增成功！");
				break;
			} else {
				System.out.println("新增失败！");
				break;
			}

		default:
			break;
		}
	}

	private static void updateParticipant() {
		int empId = 0;
		int meetingId = 0;

		System.out.print("请输入员工编号：");
		try {
			String name = scanner.nextLine();
			empId = Integer.parseInt(name);
		} catch (Exception e) {
			System.out.println("请输入数字：");
			updateParticipant();
		}

		System.out.println("修改会议编号，会议主题，到场情况：");
		System.out.print("请输入会议编号：");
		try {
			String idsString = scanner.nextLine();
			meetingId = Integer.parseInt(idsString);
		} catch (Exception e) {
			System.out.println("请输入数字：");
		}

		System.out.print("请输入会议主题：");
		String conferenceTheme = scanner.nextLine();

		System.out.print("请输入到场情况（1,0）：");
		String presentSituation = scanner.nextLine();

		System.out.println("是否更新参与人员信息:");
		System.out.println("是否更新信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			participant = new Participant(empId, meetingId, conferenceTheme, presentSituation);
			boolean bool = participantServiceImpl.edit(participant);
			if (bool) {
				System.out.println("修改成功！");
				break;
			} else {
				System.out.println("修改失败！");
				break;

			}

		default:
			break;
		}
	}

	/**
	 * 根据会议编号删除，参会人员
	 */
	private static void deleteParticipant() {
		System.out.print("请输入员工编号：");
		String idString = scanner.nextLine();
		int empId = Integer.parseInt(idString);
		participant.setEmpId(empId);

		System.out.println("是否删除参与人员信息:");
		System.out.println("是否删除信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			boolean bool = participantServiceImpl.deleteById(empId);
			if (bool) {
				System.out.println("删除成功！");
				break;
			} else {
				System.out.println("删除失败！");
				break;
			}

		default:
			break;
		}
	}

	private static void selectParticipant() {
		List<Participant> list = participantServiceImpl.findAll();
		System.out.println("员工编号 \t会议编号 \t会议主题  \t是否到场");
		for (Participant participant : list) {
			System.out.println(participant.getEmpId() + "\t" + participant.getMeetingId() + "\t"
					+ participant.getConferenceTheme() + "\t" + participant.getPresentSituation());
		}
	}

	public void show() {
		Boolean bool = true;
		while (bool) {
			System.out.println("========================================");
			System.out.println("1.办公准备                                    ");
			System.out.println("2.参与会议表                                ");
			System.out.println("3.会议地点                                    ");
			System.out.println("4.返回上一级                                ");
			System.out.println("========================================");
			String an = scanner.nextLine();
			switch (an) {
			case "1":
				System.out.println("您选择了，办公准备：");
				show4();
				break;
			case "2":
				System.out.println("您选择了，参与会议表：");
				show2();
				break;
			case "3":
				System.out.println("你选择了，会议地址表：");
				show3();
				break;
			case "4":
				bool = false;
				break;

			default:
				System.out.println("输入有误，请重新输入：");
				break;
			}
		}
	}

	public void show2() {
		Boolean bool = true;
		while (bool) {
			System.out.println("========================================");
			System.out.println("1.新增                                      ");
			System.out.println("2.修改                                      ");
			System.out.println("3.删除                                      ");
			System.out.println("4.查询                                      ");
			System.out.println("5.返回上一级                          ");
			System.out.println("========================================");
			String an = scanner.nextLine();
			switch (an) {
			case "1":
				try {
					insertParticipant();
					System.out.println("3秒后返回............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "2":
				try {
					updateParticipant();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "3":
				try {
					deleteParticipant();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "4":
				selectParticipant();
				System.out.println("输入任意键返回");
				String string = scanner.nextLine();
				System.out.println(string);
				break;
			case "5":
				bool = false;
				break;

			default:
				break;
			}
		}

	}

	/**
	 * 添加会议地址信息
	 */
	private static void insertMeetingPlace() {
		int galleyful = 0;
		System.out.print("请输入，会议地址：");
		String meetingPlace2 = scanner.nextLine();

		System.out.print("请输入,容纳人数：");
		String count = scanner.nextLine();
		try {
			galleyful = Integer.parseInt(count);
		} catch (Exception e) {
			System.out.println("输入出错！");
		}

		System.out.print("请输入，分配的资源：");
		String allocateResource = scanner.nextLine();

		System.out.println("是否添加信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":

			meetingPlace = new MeetingPlace(meetingPlace2, galleyful, allocateResource);

			boolean bool = meetingPlaceServiceImpl.add(meetingPlace);
			if (bool) {
				System.out.println("添加成功！");
				break;
			} else {
				System.out.println("添加失败！");
				break;
			}

		default:
			break;
		}

	}

	/**
	 * 根据会议地点删除
	 */
	private static void deleteMeetingPlace() {
		System.out.print("请输入，会议地点：");
		String meetingPlace2 = scanner.nextLine();
		meetingPlace.setMeetingPlace(meetingPlace2);

		System.out.println("是否删除地点信息:");
		System.out.println("是否删除信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			boolean bool = meetingPlaceServiceImpl.delete(meetingPlace);
			if (bool) {
				System.out.println("删除成功！");
				break;
			} else {
				System.out.println("删除失败，请查询会议地址是否存在！");
				break;
			}


		default:
			break;
		}
	}

	/**
	 * 根据会议地点修改信息
	 */
	private static void updateMeetingPlace() {
		int galleyful = 0;
		System.out.print("请输入，会议地址：");
		String meetingPlace2 = scanner.nextLine();

		System.out.println("修改容纳人数和分配资源：");
		System.out.print("请输入,容纳人数：");
		String count = scanner.nextLine();
		try {
			galleyful = Integer.parseInt(count);
		} catch (Exception e) {
			System.out.print("输入出错，请输入数字");
		}

		System.out.print("请输入，分配的资源：");
		String allocateResource = scanner.nextLine();

		System.out.println("是否更新地点信息:");
		System.out.println("是否更新信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			meetingPlace = new MeetingPlace(meetingPlace2, galleyful, allocateResource);

			boolean bool = meetingPlaceServiceImpl.edit(meetingPlace);
			if (bool) {
				System.out.println("修改失败！");
				break;
			} else {
				System.out.println("修改失败！");
				break;
			}

		default:
			break;
		}
	}

	/**
	 * 查询会议地点信息
	 */
	private static void selectMeetingPlace() {
		List<MeetingPlace> list = meetingPlaceServiceImpl.findAll();
		System.out.println("会议地点 \t 容纳人数 \t 配置资源");
		for (MeetingPlace meetingPlace : list) {
			System.out.println(meetingPlace.getMeetingPlace() + "\t" + meetingPlace.getGalleryful() + "\t"
					+ meetingPlace.getAllocateResourcess());
		}
	}

	public void show3() {
		boolean bool = true;
		while (bool) {
			System.out.println("========================================");
			System.out.println("1.新增                                      ");
			System.out.println("2.修改                                      ");
			System.out.println("3.删除                                      ");
			System.out.println("4.查询                                      ");
			System.out.println("5.返回上一级                          ");
			System.out.println("========================================");
			String an = scanner.nextLine();
			switch (an) {
			case "1":
				try {
					insertMeetingPlace();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "2":
				try {
					updateMeetingPlace();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "3":
				try {
					deleteMeetingPlace();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "4":
				selectMeetingPlace();
				System.out.println("输入任意键返回");
				String string = scanner.nextLine();
				System.out.println(string);
				break;
			case "5":
				bool = false;
				break;

			default:
				break;
			}
		}
	}

	/**
	 * 增加会议
	 */
	private static void insertPrepareMeeting() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		int meetingId = 0;
		Date startTime = null;
		Date endTime = null;

		System.out.print("请输入，会议编号（数字）：");
		try {
			String id = scanner.nextLine();
			meetingId = Integer.parseInt(id);

		} catch (Exception e) {
			System.out.println("输入出错");
		}

		System.out.print("请输入，主讲人：");
		String speaker = scanner.nextLine();

		System.out.print("请输入，会议类型：");
		String meetingForma = scanner.nextLine();

		System.out.print("请输入，会议主题：");
		String meetingTheme = scanner.nextLine();

		System.out.print("请输入，会议开始时间（yyyy-MM-dd HH:mm:ss）：");
		try {
			String date = scanner.nextLine();
			startTime = simpleDateFormat.parse(date);
		} catch (Exception e) {
			System.out.println("输入时间类型出错：");
		}

		System.out.print("请输入，会议结束时间（yyyy-MM-dd HH:mm:ss）：");
		try {
			String date2 = scanner.nextLine();
			endTime = simpleDateFormat.parse(date2);
		} catch (Exception e) {
			System.out.println("输入时间类型出错：");
		}

		System.out.print("请输入，会议地点：");
		String meetingPlace2 = scanner.nextLine();

		System.out.print("请输入，会议内容：");
		String meetingContent = scanner.nextLine();

		System.out.println("是否添加会议信息:");
		System.out.println("是否添加信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			prepareMeeting = new PrepareMeeting(meetingId, speaker, meetingForma, meetingTheme, startTime, endTime,
					meetingPlace2, meetingContent);
			boolean bool = prepareMeetingServiceImpl.add(prepareMeeting);
			if (bool) {
				System.out.println("添加成功");
				break;
			} else {
				System.out.println("添加失败");
				break;
			}

		default:
			break;
		}
	}

	/**
	 * 删除会议
	 */
	private static void deletePrepareMeeting() {
		int meetingId = 0;
		System.out.print("请输入，要删除的会议编号：");
		try {
			String id = scanner.nextLine();
			meetingId = Integer.parseInt(id);
		} catch (Exception e) {
			System.out.println("输入会议编号失败请重新输入：");
			deletePrepareMeeting();
		}

		System.out.println("是否删除会议信息:");
		System.out.println("是否删除信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			boolean bool = meetingPlaceServiceImpl.deleteById(meetingId);
			if (bool) {
				System.out.println("删除成功");
				break;
			} else {
				System.out.println("删除失败");
				break;
			}

		default:
			break;
		}
	}

	/**
	 * 根据会议编号修改其他信息
	 */
	private static void updatePrepareMeeting() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		int meetingId = 0;
		Date startTime = null;
		Date endTime = null;
		System.out.print("请输入，会议编号（数字）：");
		try {
			String id = scanner.nextLine();
			meetingId = Integer.parseInt(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("修改");
		System.out.print("请输入，主讲人：");
		String speaker = scanner.nextLine();

		System.out.print("请输入，会议类型：");
		String meetingForma = scanner.nextLine();

		System.out.print("请输入，会议主题：");
		String meetingTheme = scanner.nextLine();

		System.out.print("请输入，会议开始时间：");
		try {
			String date = scanner.nextLine();
			startTime = simpleDateFormat.parse(date);
		} catch (Exception e) {
			System.out.println("输入时间类型出错：");
		}

		System.out.print("请输入，会议结束时间：");
		try {
			String date2 = scanner.nextLine();
			endTime = simpleDateFormat.parse(date2);
		} catch (Exception e) {
			System.out.println("输入时间类型出错：");
		}

		System.out.print("请输入，会议地点：");
		String meetingPlace2 = scanner.nextLine();

		System.out.print("请输入，会议内容：");
		String meetingContent = scanner.nextLine();

		System.out.println("是否更新会议信息:");
		System.out.println("是否更新信息：是(1)	否(2)");
		String choose = scanner.nextLine();
		switch (choose) {
		case "1":
			prepareMeeting = new PrepareMeeting(meetingId, speaker, meetingForma, meetingTheme, startTime, endTime,
					meetingPlace2, meetingContent);
			boolean bool = prepareMeetingServiceImpl.edit(prepareMeeting);
			if (bool) {
				System.out.println("修改成功");
				break;
			} else {
				System.out.println("修改失败");
				break;
			}

		default:
			break;
		}
	}

	/**
	 * 查询所有信息
	 */
	private static void selectPrepareMeeting() {
		List<PrepareMeeting> list = prepareMeetingServiceImpl.findAll();
		System.out.println("会议编号 \t 主讲人 \t会议类型 \t 会议主题 \t 开始时间 \t\t\t 结束时间 \t\t\t 会议地点 \t会议内容");
		for (PrepareMeeting prepareMeeting : list) {
			System.out.println(prepareMeeting.getId() + "\t" + prepareMeeting.getSpeaker() + "\t"
					+ prepareMeeting.getMeetingForma() + "\t" + prepareMeeting.getMeetingTheme() + "\t"
					+ prepareMeeting.getStartTime() + "\t" + prepareMeeting.getEndTime() + "\t"
					+ prepareMeeting.getMeetingPlace() + "\t" + prepareMeeting.getMeetingContent());
		}
	}

	public static void show4() {
		boolean bool = true;
		while (bool) {
			System.out.println("========================================");
			System.out.println("1.新增                                      ");
			System.out.println("2.修改                                      ");
			System.out.println("3.删除                                      ");
			System.out.println("4.查询                                      ");
			System.out.println("5.返回上一级                          ");
			System.out.println("========================================");
			String an = scanner.nextLine();
			switch (an) {
			case "1":
				try {
					insertPrepareMeeting();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "2":
				try {
					updatePrepareMeeting();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "3":
				try {
					deletePrepareMeeting();
					System.out.println("3秒后返回.............");
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					System.out.println("返回失败！");
					return;
				}
				break;
			case "4":
				selectPrepareMeeting();
				System.out.println("输入任意键返回");
				String string = scanner.nextLine();
				System.out.println(string);
				break;
			case "5":
				bool = false;
				break;

			default:
				break;
			}
		}
	}

	public static void main(String[] args) {
		MeetingView oaSystem = new MeetingView();
		oaSystem.show();
	}
}
